//app.js
import { request } from './utils/api'

App({
  onLaunch: function () {
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        wx.setStorage({
          data: res.code,
          key: 'code',
        })
        request({
          url: '/zhongyisheji-applet/login/getOpenid',
          method: 'POST',
          data: {
            code: res.code
          }
        }).then(res => {
          console.log(res);
          wx.setStorage({
            data: res.data,
            key: 'codeData',
          })
        })
      }
    })
  },
  show111: true,
  //全局点击事件
  editTabbar: function () {
    console.log(this.globalData);
    var tabbar = this.globalData.tabBar;
    var currentPages = getCurrentPages();
    var that = currentPages[currentPages.length - 1];
    var pagePath = that.route;
    (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
    for (var i in tabbar.list) {
      tabbar.list[i].selected = false;
      (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
    }
    that.setData({
      tabbar: tabbar
    });
  },
  // 图片预览
  onPreviewImg(url) {
    wx.previewImage({
      urls: [this.globalData.imgBaseUrl + url] // 需要预览的图片http链接列表
    })
  },
  globalData: {
    userInfo: null,
    statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
    tabBar: {
      "backgroundColor": "#ffffff",
      "color": "#979795",
      "selectedColor": "#1c1c1b",
      "list": [
        {
          "pagePath": "/pages/tabbars/home/home",
          "iconPath": "/tabbarComponent/icon/home.png",
          "selectedIconPath": "/tabbarComponent/icon/home1.png",
          "text": "找项目"
        },
        {
          "pagePath": "/pages/tabbars/talents/talents",
          "iconPath": "/tabbarComponent/icon/talents.png",
          "selectedIconPath": "/tabbarComponent/icon/talents1.png",
          "text": "找人才"
        },
        {
          "pagePath": "/pages/index/index",
          "iconPath": "/tabbarComponent/icon/book.png",
          "selectedIconPath": "/tabbarComponent/icon/book1.png",
          "isSpecial": true,
          "text": "学知识"
        },
        {
          "pagePath": "/pages/tabbars/message/message",
          "iconPath": "/tabbarComponent/icon/message.png",
          "selectedIconPath": "/tabbarComponent/icon/message1.png",
          "text": "消息"
        },
        {
          "pagePath": "/pages/tabbars/mine/mine",
          "iconPath": "/tabbarComponent/icon/mine.png",
          "selectedIconPath": "/tabbarComponent/icon/mine1.png",
          "text": "我的"
        }
      ]
    },
    systemInfo: wx.getSystemInfoSync(),
    // 图片基础路径
    imgBaseUrl: 'https://applet.zhongyisheji.com/zhongyisheji-applet/',
    // imgBaseUrl: 'http://192.168.2.175:9020/zhongyisheji-applet/',
    // 图片上传路径
    imgUploadUrl: 'https://applet.zhongyisheji.com/zhongyisheji-applet/upload/public/uploadImage',
    // imgUploadUrl: 'http://192.168.2.175:9020/zhongyisheji-applet/upload/public/uploadImage',
    // 请求基础路径
    // bsaeUrl: 'http://192.168.2.175:9020',
    bsaeUrl: 'https://applet.zhongyisheji.com'
  }
})